// +build ignore

package main

import (
	"databox-broker/conf"
	"databox-broker/log"
	"databox-broker/rpc"
	"net/url"
	"time"
)

func main() {
	cf := &conf.Config{
		Log: &conf.Log{
			Path: "./var/log",
		},
		App: &conf.App{
			Debug: false,
		},
	}
	log.InitLogger(cf)
	urlDefine := &url.URL{Scheme: "ws", Host: "localhost:34543", Path: "/api/v1/bind"}
	r, err := rpc.NewJSONRPC(&rpc.JSONRPCOpts{
		URL: urlDefine,
	})
	if err != nil {
		panic(err)
	}

	// notice send
	go func() {
		for {
			<-time.After(time.Second * 10)
			relpy := ""
			if err := r.Call(rpc.CallTypeNotice, "hi", "warning!", &relpy); err != nil {
				log.Logger.Errorf("call notice err: %s", err)
				continue
			}
		}
	}()

	// send error data
	go func() {
		for {
			<-time.After(time.Second * 5)
			relpy := ""
			err := r.Call(rpc.CallTypeRequest, "oo", "nikankan", &relpy)
			if err != nil {
				log.Logger.Errorf("call request err: %s", err)
				continue
			}
			log.Logger.Infof("call request: %s", relpy)
		}
	}()

	// request send
	for {

		relpy := ""
		err := r.Call(rpc.CallTypeRequest, "test", "hello", &relpy)
		if err != nil {
			log.Logger.Errorf("call request err: %s", err)
			continue
		}
		log.Logger.Infof("call request: %s", relpy)
		<-time.After(time.Second * 2)

	}
}
